
/* 一些基本定义，包括一个全局的
 永久对象内存池(可配置，2M)用于分配内存管理相关的数据结构
 */
#include "base_malloclib.h"

/* 操作系统层 */
#include <metalc/mlos/mmapheap.h>
DEF_MMAPHEAP_MLAYER(mmapheap_normal, BIT(21), SIZE_1G, SIZE_64G, 0, 0)

#define BINBUDDY_APDS	sffwd
/* 定义buddy */
#include <metalc/mlayer/binbuddy.h>
static buddy_obj_t *pbd;
/* 必须管理到 48 */
DEF_BUDDYEXT_MLAYER(buddy_ext, pbd, 16, HDEF_PTR_BITS, 21, page_alloc)


/* 定义wfspan */
#include <metalc/mlayer/wfspan_nomblock.h>
DEF_CLS_SUPER_CLS2SZTBL(super, 4, 15, MANTISSA_BITS_DEFAULT, LOW_BITS_DEFAULT)
/* 使用转换表加速 */
SIN hword_t unitsz2maxnr(szcls_t cls){
	/* 提前算好的, 39个map映射表 */
	static const uint16_t maptable[] = {4088, 2044, 1362, 1022, 817, 681, 584, 511, 408, 340, 292, 255, 204, 170, 146, 127, 102, 85, 73, 63, 51, 42, 36, 31, 25, 21, 18, 15, 12, 10, 9, 7, 6, 5, 4, 3, 3, 2, 2};
	// int asdas[sizeof(maptable) / sizeof(word_t)];
	ASSERT(cls < _clsnr_super);
	return (hword_t)maptable[cls];
}
DEF_WFSLAB_MLAYER(wfspan, 4, 15, BIT(16), 64, 0, 1, super, unitsz2maxnr, mlcc_palloc)


/* 组合 */
COMPOSE_MLAYER(malloc_wfslab, mallocapi, wfspan, buddy_ext, mmapheap_normal)

/* 定义线程私有信息，PTHREAD表示针对Unix Pthread环境 */
DEF_MTLS_PTHREAD(GET_MLAYER_OBJNR(malloc_wfslab), 4096, mlcc_palloc, mp_coreid)
/* 系统初始化执行的回调 */
DEF_SYSINIT(malloc_perm_pool, malloc_wfslab, mtls)
/* 控制流(线程)初始化执行的回调 */
DEF_CFLOWINIT(mtls, malloc_wfslab)
/* */
DEF_CFLOWFIN(mtls)
DEF_SYSFIN(__omega)